this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


$(document).ready(function() {    
    
    // --- Hide Image ---
    $( '#ajaxLoadAni' ).fadeOut( 'slow' );
    
    // --- Calendar Function ---
    $( ".datepicker" ).datepicker({
            changeMonth: true,
            changeYear: true,
            yearRange:"-100:y"
    });
    
    $( ".datepicker2" ).datepicker({
            changeMonth: true,
            changeYear: true,
            minDate: "-15y",
            maxDate: "y"
    });
	
	$( ".datepicker_books" ).datepicker({
      changeMonth: true,
      changeYear: true,
	   yearRange: "-40:+0"
    });
	
    $( ".datepicker-payment" ).datepicker({
		changeMonth: true,
		maxDate: "0m",
		defaultDate: new Date()
    });	
	
    
	$( ".datepicker3" ).datepicker({
            changeMonth: true,
            changeYear: true,
        });
		
	 // --- Student Stat ---
    $( '.studentStat' ).click(function(){
        var a = $('input[name=student_status]:checked').val();
        if(a=='new')
        {
            $('input[name=student_id]').val('');
            $('#studentId').css({ "display" : "none" });
        }
        else
        {
            $('#studentId').css({ "display" : "block" });
        }
    });
    
    // --- Modal ---
    $( '#msgDialog' ).dialog({
		draggable:false,
        autoOpen: false,
		resizable: false,
		height:400,
		modal: true,
        buttons: {
            'Ok': function() {
                $( this ).dialog( 'close' );
            }
        }
    });

    /** Colapsible Panel **/
    $(document).on('click', '.panel-heading span.clickable', function(e){
	    var $this = $(this);
		if(!$this.hasClass('panel-collapsed')) {
			$this.parents('.panel').find('.panel-body').slideUp();
			$this.addClass('panel-collapsed');
			$this.find('i').removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
		} else {
			$this.parents('.panel').find('.panel-body').slideDown();
			$this.removeClass('panel-collapsed');
			$this.find('i').removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
		}
	})

	/** Jquery accordion **/
	$( ".jqry_accordion" ).accordion();
    
    // --- Tab ---
    // Tabs
    $('#tabs').tabs();
    
    // --- Get The Base URL ---
    var baseurl = $('#baseurl').val();    
    
    // --- Confirm Deletion ---
    $( 'a.confirm' ).click(function(e){
		
        e.preventDefault();
        var theHREF = $(this).attr("href");
		var title = $(this).attr("title");
		var target = $(this).attr('target');
		var closeOnConfirm = $(this).attr('data-download');

        if(!title ){
			$( '#msgDialog > p' ).html( 'Are You Sure?' );
		}else{
			$( '#msgDialog > p' ).html( title );
		}
		
        $( '#msgDialog' ).dialog( 'option', 'title', 'Confirm' );
        $("#msgDialog").dialog('option', 'buttons', {
                "Confirm" : function() {
						if(typeof closeOnConfirm == "undefined")
						{	
							if(typeof  target == "undefined")
							{
								window.location.href = theHREF;
							}else{
								$(this).dialog("close");
								window.open(theHREF);
							}
						}else{
							window.open(theHREF);
							$(this).dialog("close");
						}
                    },
                "Cancel" : function() {
						$(this).dialog("close");

                    }
                });
		
		$("#msgDialog").dialog("open");
		$('.ui-dialog-buttonpane').find('button').addClass('btn btn-mini btn-primary');

    });
    
    // --- Create Subject To Curriculum Record ---
    $( '.subject_to_curriculum' ).click(function(){        
            
            $( '#ajaxLoadAni' ).fadeIn( 'slow' );
            
            var target = $(this).attr("id");
            
            $.ajax({
                dataType : 'json',
                url: baseurl + 'admin/create_subject_to_curriculum',
                type: 'POST',
                data: $( '#myform' + target ).serialize(),
                
                success: function( response ) {
                    
                        $( '#msgDialog > p' ).html( 'inserted' );
                        $( '#msgDialog' ).dialog( 'option', 'title', 'Success' ).dialog( 'open' );
                        $( '#ajaxLoadAni' ).fadeOut( 'slow' );
                        
                    
                }

            });
            
            return false;
    });
	
	// CHECK ALL CHECKBOXES
	$('.check_all').click(function(){
		
		var id = $(this).attr('id');
		
		if($(this).is(':checked')){
			$('.'+id).attr('checked', 'checked');
		}
		else if($(this).not(':checked')){
			$('.'+id).removeAttr('checked');
		}
	});

	//function confirm-auto start
	$( 'a.confirm-auto' ).click(function(e){
			e.preventDefault();
			$('body').addClass('disable_scroll');
			$(this).addClass('current_pick');
			
			var theHREF = $(this).attr("href");
			var title = $(this).attr("title");
			if(!title ){
				$( '#msgDialog > p' ).html( 'Are You Sure?' );
			}else{
				$( '#msgDialog > p' ).html( title );
			}
			$('#msgDialog' ).dialog( 'option', 'title', 'Confirm Action' );
			$('#msgDialog' ).dialog( {
				resizable: false,
				height:140,
				modal: true
			});
			
			$("#msgDialog").dialog('option', 'buttons', {
					"Confirm" : function() {
						$('body').removeClass('disable_scroll');
						$(this).dialog("close");
							$.ajax({
									type: 'POST',
									url: theHREF,
									data:{
										'jquery' : true
									},
									beforeSend: function() {
										$('body').addClass('disable_scroll');
										$('#loader').show();
									},
									 complete: function(){
										$('body').removeClass('disable_scroll');
										$('#loader').hide('slow');
									},
									success: function(msg){
										if(msg == 'true')
										{
											alert("Process was successfully Done");
											$('a.current_pick').parents('tr.profile_box').hide(2000);
										}else{
											alert("Process encountered an error");
										}
									},
									error: function (msg){
										alert("An error has occured");
									}
							});
						},
					"Cancel" : function() {
						$('body').removeClass('disable_scroll');
						$(this).dialog("close");
						}
			});

			$("#msgDialog").dialog("open");
    });

	$('#fee').change(function(){
		var url = $(this).attr('url');
		var opt = $(this).val();
		if(opt == 'is_misc_fee' || opt == 'is_tuition_fee' || opt == 'is_cca_fee')
		{
			$.get(url, function(data) {
			  $('.dynamic-dropdown').html(data).show(50);
			});
		}else{
			$('.dynamic-dropdown').hide(50);
		
		}
	});
	
	$("#autosearch").keyup(function()
	{
		var value = this.value;

		$("table").find("tr").each(function(index) {
			if (index === 0) return;
			var id = $(this).find("td").first().text();
			$(this).toggle(id.indexOf(value) !== -1);
		});
	});
	
	
	$('.dac').on('click change',function (e) {
		e.preventDefault();
		$(this).attr('disabled',true);
		$(this).text('Processing please wait ...');
	});
	
	
	
	$('.checkbox-all').click(function(e){
		e.preventDefault();
		var checked = $(this).data('checked');
		$('table').find(':checkbox').attr('checked', !checked);
		$(this).data('checked', !checked);
	});
	
	
	 $( '.alert-me-when-click' ).click(function(e){
		var title = $(this).attr("title");
		var desc = $(this).attr("desc");
		
		var modal_title = '';
		var modal_body = '';
		
        if(!title){
			modal_title = 'Are You Sure';
		}else{
			modal_title = title;
		}
		
		if(!desc){
			modal_body = 'Please Wait.';
		}else{
			modal_body = desc;
		}
    
        $("#msgDialog").dialog('option','height',400);
        $("#msgDialog").dialog('option','buttons','');
		
		
		$('.ui-dialog-buttonpane').find('button').addClass('btn btn-mini btn-primary');
		$(".ui-dialog-titlebar-close").hide();
		
		$( '#msgDialog > div.content' ).html(modal_body);
		$( '#msgDialog > p' ).html( title );
		$("#msgDialog").dialog("open");
    });
	
	
	$('a.dsec').on('click',function(e){
		e.preventDefault();
		var url = $(this).attr('href');
		window.location.href = url;
	});
	
	$('.redirect-auto').on('change',function(e){
		e.preventDefault();
		var url= $(this).attr('url');
		var segment = $(this).val();
		var doit = function(url,segment){
			window.location.href = url+"/"+segment
		};

		$("#msgDialog").dialog('option','height',200);
		$( '#msgDialog > p' ).html( 'Please Wait while system Generates Billing.' );
		$('.ui-dialog-buttonpane').find('button').remove();
		$('.ui-dialog-titlebar').find('button').remove();
		$( '#msgDialog > div.content' ).text('Please Wait.');
		$(".ui-dialog-titlebar-close").hide();
		 $("#msgDialog").dialog('option','buttons','');
		$( '#msgDialog > p' ).text( 'Redirecting' );
		$("#msgDialog").dialog("open");
		
		setInterval(doit(url,segment),1000);
		
	});
	
	$('.tp').tooltip('show');
	
	//for tooltip
	//$(".tipper").tooltipster();
});// --- end document ready ---


/* BOOTSTRAP MODAL */
function custom_modal(title, html)
{
	
	$('#alertModal_Body').html(''); 
	$('#alertModal_Label').text(title); //SET MODAL TITLE
	$('#alertModal_Body').html(html); //SET MODAL CONTENT
	$('#alertModal').modal('show'); //SHOW MODAL
}
